//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.common.cas;

import java.util.Map;

import com.google.common.collect.Maps;
import org.jasig.cas.client.authentication.AuthenticationFilter;
import org.jasig.cas.client.session.SingleSignOutFilter;
import org.jasig.cas.client.session.SingleSignOutHttpSessionListener;
import org.jasig.cas.client.util.AssertionThreadLocalFilter;
import org.jasig.cas.client.util.HttpServletRequestWrapperFilter;
import org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

@Configuration
@ConfigurationProperties(
    prefix = "cas"
)
@ComponentScan({"com.ruoyi.common.cas","org.jasig.cas.client"})
public class CasConfiguration implements InitializingBean {
    public static final String DEFAULT_CAS_CALLBACK = DefaultCASLoginCallback.class.getName();
    public static final String SWAGGER_IGNORE_PATTERN = "swagger-ui.html|/webjars|/swagger-resources|/v2/api-docs";
    public static final String FW_ENDPOINT_IGNORE_PATTERN = "/health$|/info$";
    public static final String DEFAULT_IGNORE_PATTERN = "/health$|/info$|swagger-ui.html|/webjars|/swagger-resources|/v2/api-docs";
    private String casServerUrl;
    private String casServerLoginUrl;
    private String casServerLogoutUrl;
    private String casServerUrlPrefix;
    private String casClientUrl;
    private String casClientLoginUrl;
    private String homePage;
    private String casLoginCallbackClass;
    private String authenticationRedirectStrategyClass;
    private String customIgnorePattern;
    private String ignorePattern;
    private String redirectAfterValidation;
    private String exceptionOnValidationFailure;
    @Value("${server.servlet.context-path:}")
    private String contextPath;

    @Bean
    public ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> listenerRegistration3() {
        return new ServletListenerRegistrationBean(new SingleSignOutHttpSessionListener());
    }

    @Bean
    public FilterRegistrationBean singleSignOutFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new SingleSignOutFilter(), new ServletRegistrationBean[0]);
        registration.addUrlPatterns(new String[]{"/*"});
        registration.setName("CAS Single Sign Out Filter");
        return registration;
    }

    @Bean
    public FilterRegistrationBean authenticationFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new AuthenticationFilter(), new ServletRegistrationBean[0]);
        registration.addUrlPatterns(new String[]{"/*"});
        registration.setName("CAS Authentication Filter");
        Map<String, String> initParameters = Maps.newHashMap();
        initParameters.put("casServerLoginUrl", this.casServerLoginUrl);
        initParameters.put("serverName", this.casClientUrl);
        initParameters.put("ignorePattern", this.ignorePattern);
        if (this.authenticationRedirectStrategyClass != null) {
            initParameters.put("authenticationRedirectStrategyClass", this.authenticationRedirectStrategyClass);
        }

        registration.setInitParameters(initParameters);
        return registration;
    }

    @Bean
    public FilterRegistrationBean cas20ProxyReceivingTicketValidationFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new Cas20ProxyReceivingTicketValidationFilter(), new ServletRegistrationBean[0]);
        registration.addUrlPatterns(new String[]{"/*"});
        registration.setName("CAS Validation Filter");
        Map<String, String> initParameters = Maps.newHashMap();
        initParameters.put("casServerUrlPrefix", this.casServerUrlPrefix);
        initParameters.put("serverName", this.casClientUrl);
        if (this.redirectAfterValidation != null) {
            initParameters.put("redirectAfterValidation", this.redirectAfterValidation);
        }

        if (this.exceptionOnValidationFailure != null) {
            initParameters.put("exceptionOnValidationFailure", this.exceptionOnValidationFailure);
        }

        registration.setInitParameters(initParameters);
        return registration;
    }

    @Bean
    public FilterRegistrationBean httpServletRequestWrapperFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new HttpServletRequestWrapperFilter(), new ServletRegistrationBean[0]);
        registration.addUrlPatterns(new String[]{"/*"});
        registration.setName("CAS HttpServletRequest Wrapper Filter");
        return registration;
    }

    @Bean
    public FilterRegistrationBean assertionThreadLocalFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new AssertionThreadLocalFilter(), new ServletRegistrationBean[0]);
        registration.addUrlPatterns(new String[]{"/*"});
        registration.setName("CAS Assertion Thread Local Filter");
        return registration;
    }

    @Bean
    public FilterRegistrationBean riskPlatPermissionFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new RiskPlatPermissionFilter(), new ServletRegistrationBean[0]);
        registration.addUrlPatterns(new String[]{"/*"});
        registration.setName("CAS riskPlat Permission Filter");
        return registration;
    }

    @Bean
    public ServletContextInitializer casServletContextInitializer() {
        return (servletContext) -> {
            servletContext.setInitParameter("cas-client-class", this.casLoginCallbackClass);
        };
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.casServerLoginUrl = this.casServerLoginUrl != null ? this.casServerLoginUrl : this.getCasServerUrl() + "/cas/login";
        this.casServerLogoutUrl = this.casServerLogoutUrl != null ? this.casServerLogoutUrl : this.getCasServerUrl() + "/cas/logout";
        this.casServerUrlPrefix = this.casServerUrlPrefix != null ? this.casServerUrlPrefix : this.getCasServerUrl() + "/cas";
        this.casClientLoginUrl = this.casClientLoginUrl != null ? this.casClientLoginUrl : this.getCasClientUrl() + this.ifPrifix() + "/cas/login";
        this.ignorePattern = this.ignorePattern != null ? this.ignorePattern : "/health$|/info$|swagger-ui.html|/webjars|/swagger-resources|/v2/api-docs" + (this.customIgnorePattern == null ? "" : "|" + this.customIgnorePattern);
    }

    private String ifPrifix() {
        return !StringUtils.isEmpty(this.contextPath) && !"/".equals(this.contextPath) ? this.contextPath : "";
    }

    public CasConfiguration() {
        this.casLoginCallbackClass = DEFAULT_CAS_CALLBACK;
    }

    public String getCasServerUrl() {
        return this.casServerUrl;
    }

    public String getCasServerLoginUrl() {
        return this.casServerLoginUrl;
    }

    public String getCasServerLogoutUrl() {
        return this.casServerLogoutUrl;
    }

    public String getCasServerUrlPrefix() {
        return this.casServerUrlPrefix;
    }

    public String getCasClientUrl() {
        return this.casClientUrl;
    }

    public String getCasClientLoginUrl() {
        return this.casClientLoginUrl;
    }

    public String getHomePage() {
        return this.homePage;
    }

    public String getCasLoginCallbackClass() {
        return this.casLoginCallbackClass;
    }

    public String getAuthenticationRedirectStrategyClass() {
        return this.authenticationRedirectStrategyClass;
    }

    public String getCustomIgnorePattern() {
        return this.customIgnorePattern;
    }

    public String getIgnorePattern() {
        return this.ignorePattern;
    }

    public String getRedirectAfterValidation() {
        return this.redirectAfterValidation;
    }

    public String getExceptionOnValidationFailure() {
        return this.exceptionOnValidationFailure;
    }

    public String getContextPath() {
        return this.contextPath;
    }

    public void setCasServerUrl(final String casServerUrl) {
        this.casServerUrl = casServerUrl;
    }

    public void setCasServerLoginUrl(final String casServerLoginUrl) {
        this.casServerLoginUrl = casServerLoginUrl;
    }

    public void setCasServerLogoutUrl(final String casServerLogoutUrl) {
        this.casServerLogoutUrl = casServerLogoutUrl;
    }

    public void setCasServerUrlPrefix(final String casServerUrlPrefix) {
        this.casServerUrlPrefix = casServerUrlPrefix;
    }

    public void setCasClientUrl(final String casClientUrl) {
        this.casClientUrl = casClientUrl;
    }

    public void setCasClientLoginUrl(final String casClientLoginUrl) {
        this.casClientLoginUrl = casClientLoginUrl;
    }

    public void setHomePage(final String homePage) {
        this.homePage = homePage;
    }

    public void setCasLoginCallbackClass(final String casLoginCallbackClass) {
        this.casLoginCallbackClass = casLoginCallbackClass;
    }

    public void setAuthenticationRedirectStrategyClass(final String authenticationRedirectStrategyClass) {
        this.authenticationRedirectStrategyClass = authenticationRedirectStrategyClass;
    }

    public void setCustomIgnorePattern(final String customIgnorePattern) {
        this.customIgnorePattern = customIgnorePattern;
    }

    public void setIgnorePattern(final String ignorePattern) {
        this.ignorePattern = ignorePattern;
    }

    public void setRedirectAfterValidation(final String redirectAfterValidation) {
        this.redirectAfterValidation = redirectAfterValidation;
    }

    public void setExceptionOnValidationFailure(final String exceptionOnValidationFailure) {
        this.exceptionOnValidationFailure = exceptionOnValidationFailure;
    }

    public void setContextPath(final String contextPath) {
        this.contextPath = contextPath;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof CasConfiguration)) {
            return false;
        } else {
            CasConfiguration other = (CasConfiguration)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$casServerUrl = this.getCasServerUrl();
                Object other$casServerUrl = other.getCasServerUrl();
                if (this$casServerUrl == null) {
                    if (other$casServerUrl != null) {
                        return false;
                    }
                } else if (!this$casServerUrl.equals(other$casServerUrl)) {
                    return false;
                }

                Object this$casServerLoginUrl = this.getCasServerLoginUrl();
                Object other$casServerLoginUrl = other.getCasServerLoginUrl();
                if (this$casServerLoginUrl == null) {
                    if (other$casServerLoginUrl != null) {
                        return false;
                    }
                } else if (!this$casServerLoginUrl.equals(other$casServerLoginUrl)) {
                    return false;
                }

                Object this$casServerLogoutUrl = this.getCasServerLogoutUrl();
                Object other$casServerLogoutUrl = other.getCasServerLogoutUrl();
                if (this$casServerLogoutUrl == null) {
                    if (other$casServerLogoutUrl != null) {
                        return false;
                    }
                } else if (!this$casServerLogoutUrl.equals(other$casServerLogoutUrl)) {
                    return false;
                }

                label158: {
                    Object this$casServerUrlPrefix = this.getCasServerUrlPrefix();
                    Object other$casServerUrlPrefix = other.getCasServerUrlPrefix();
                    if (this$casServerUrlPrefix == null) {
                        if (other$casServerUrlPrefix == null) {
                            break label158;
                        }
                    } else if (this$casServerUrlPrefix.equals(other$casServerUrlPrefix)) {
                        break label158;
                    }

                    return false;
                }

                label151: {
                    Object this$casClientUrl = this.getCasClientUrl();
                    Object other$casClientUrl = other.getCasClientUrl();
                    if (this$casClientUrl == null) {
                        if (other$casClientUrl == null) {
                            break label151;
                        }
                    } else if (this$casClientUrl.equals(other$casClientUrl)) {
                        break label151;
                    }

                    return false;
                }

                Object this$casClientLoginUrl = this.getCasClientLoginUrl();
                Object other$casClientLoginUrl = other.getCasClientLoginUrl();
                if (this$casClientLoginUrl == null) {
                    if (other$casClientLoginUrl != null) {
                        return false;
                    }
                } else if (!this$casClientLoginUrl.equals(other$casClientLoginUrl)) {
                    return false;
                }

                label137: {
                    Object this$homePage = this.getHomePage();
                    Object other$homePage = other.getHomePage();
                    if (this$homePage == null) {
                        if (other$homePage == null) {
                            break label137;
                        }
                    } else if (this$homePage.equals(other$homePage)) {
                        break label137;
                    }

                    return false;
                }

                label130: {
                    Object this$casLoginCallbackClass = this.getCasLoginCallbackClass();
                    Object other$casLoginCallbackClass = other.getCasLoginCallbackClass();
                    if (this$casLoginCallbackClass == null) {
                        if (other$casLoginCallbackClass == null) {
                            break label130;
                        }
                    } else if (this$casLoginCallbackClass.equals(other$casLoginCallbackClass)) {
                        break label130;
                    }

                    return false;
                }

                Object this$authenticationRedirectStrategyClass = this.getAuthenticationRedirectStrategyClass();
                Object other$authenticationRedirectStrategyClass = other.getAuthenticationRedirectStrategyClass();
                if (this$authenticationRedirectStrategyClass == null) {
                    if (other$authenticationRedirectStrategyClass != null) {
                        return false;
                    }
                } else if (!this$authenticationRedirectStrategyClass.equals(other$authenticationRedirectStrategyClass)) {
                    return false;
                }

                Object this$customIgnorePattern = this.getCustomIgnorePattern();
                Object other$customIgnorePattern = other.getCustomIgnorePattern();
                if (this$customIgnorePattern == null) {
                    if (other$customIgnorePattern != null) {
                        return false;
                    }
                } else if (!this$customIgnorePattern.equals(other$customIgnorePattern)) {
                    return false;
                }

                label109: {
                    Object this$ignorePattern = this.getIgnorePattern();
                    Object other$ignorePattern = other.getIgnorePattern();
                    if (this$ignorePattern == null) {
                        if (other$ignorePattern == null) {
                            break label109;
                        }
                    } else if (this$ignorePattern.equals(other$ignorePattern)) {
                        break label109;
                    }

                    return false;
                }

                label102: {
                    Object this$redirectAfterValidation = this.getRedirectAfterValidation();
                    Object other$redirectAfterValidation = other.getRedirectAfterValidation();
                    if (this$redirectAfterValidation == null) {
                        if (other$redirectAfterValidation == null) {
                            break label102;
                        }
                    } else if (this$redirectAfterValidation.equals(other$redirectAfterValidation)) {
                        break label102;
                    }

                    return false;
                }

                Object this$exceptionOnValidationFailure = this.getExceptionOnValidationFailure();
                Object other$exceptionOnValidationFailure = other.getExceptionOnValidationFailure();
                if (this$exceptionOnValidationFailure == null) {
                    if (other$exceptionOnValidationFailure != null) {
                        return false;
                    }
                } else if (!this$exceptionOnValidationFailure.equals(other$exceptionOnValidationFailure)) {
                    return false;
                }

                Object this$contextPath = this.getContextPath();
                Object other$contextPath = other.getContextPath();
                if (this$contextPath == null) {
                    if (other$contextPath != null) {
                        return false;
                    }
                } else if (!this$contextPath.equals(other$contextPath)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof CasConfiguration;
    }

    @Override
    public int hashCode() {
        int result = 1;
        Object $casServerUrl = this.getCasServerUrl();
        result = result * 59 + ($casServerUrl == null ? 43 : $casServerUrl.hashCode());
        Object $casServerLoginUrl = this.getCasServerLoginUrl();
        result = result * 59 + ($casServerLoginUrl == null ? 43 : $casServerLoginUrl.hashCode());
        Object $casServerLogoutUrl = this.getCasServerLogoutUrl();
        result = result * 59 + ($casServerLogoutUrl == null ? 43 : $casServerLogoutUrl.hashCode());
        Object $casServerUrlPrefix = this.getCasServerUrlPrefix();
        result = result * 59 + ($casServerUrlPrefix == null ? 43 : $casServerUrlPrefix.hashCode());
        Object $casClientUrl = this.getCasClientUrl();
        result = result * 59 + ($casClientUrl == null ? 43 : $casClientUrl.hashCode());
        Object $casClientLoginUrl = this.getCasClientLoginUrl();
        result = result * 59 + ($casClientLoginUrl == null ? 43 : $casClientLoginUrl.hashCode());
        Object $homePage = this.getHomePage();
        result = result * 59 + ($homePage == null ? 43 : $homePage.hashCode());
        Object $casLoginCallbackClass = this.getCasLoginCallbackClass();
        result = result * 59 + ($casLoginCallbackClass == null ? 43 : $casLoginCallbackClass.hashCode());
        Object $authenticationRedirectStrategyClass = this.getAuthenticationRedirectStrategyClass();
        result = result * 59 + ($authenticationRedirectStrategyClass == null ? 43 : $authenticationRedirectStrategyClass.hashCode());
        Object $customIgnorePattern = this.getCustomIgnorePattern();
        result = result * 59 + ($customIgnorePattern == null ? 43 : $customIgnorePattern.hashCode());
        Object $ignorePattern = this.getIgnorePattern();
        result = result * 59 + ($ignorePattern == null ? 43 : $ignorePattern.hashCode());
        Object $redirectAfterValidation = this.getRedirectAfterValidation();
        result = result * 59 + ($redirectAfterValidation == null ? 43 : $redirectAfterValidation.hashCode());
        Object $exceptionOnValidationFailure = this.getExceptionOnValidationFailure();
        result = result * 59 + ($exceptionOnValidationFailure == null ? 43 : $exceptionOnValidationFailure.hashCode());
        Object $contextPath = this.getContextPath();
        result = result * 59 + ($contextPath == null ? 43 : $contextPath.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "CasConfiguration(casServerUrl=" + this.getCasServerUrl() + ", casServerLoginUrl=" + this.getCasServerLoginUrl() + ", casServerLogoutUrl=" + this.getCasServerLogoutUrl() + ", casServerUrlPrefix=" + this.getCasServerUrlPrefix() + ", casClientUrl=" + this.getCasClientUrl() + ", casClientLoginUrl=" + this.getCasClientLoginUrl() + ", homePage=" + this.getHomePage() + ", casLoginCallbackClass=" + this.getCasLoginCallbackClass() + ", authenticationRedirectStrategyClass=" + this.getAuthenticationRedirectStrategyClass() + ", customIgnorePattern=" + this.getCustomIgnorePattern() + ", ignorePattern=" + this.getIgnorePattern() + ", redirectAfterValidation=" + this.getRedirectAfterValidation() + ", exceptionOnValidationFailure=" + this.getExceptionOnValidationFailure() + ", contextPath=" + this.getContextPath() + ")";
    }
}
